function PublishTool(){
	this.isTorrentFile = function (filepath){
		if(filepath==null || filepath.length==0){
			return false;
		}
		var reg = /\.torrent$/;
		if(!filepath.toLowerCase().match(reg)){
			return false;
		}
		return true;
	};
	this.isEd2kLink = function(link){
		return this.v_link(link,"^ed2k://\\|file\\|.+\\|\\d+\\|.*/$","i");
	};
	this.isMagnetLink = function(link){
		return this.v_link(link,"^magnet:\\?.*$");
	};
	this.isThunderLink = function(link){
		return this.v_link(link,"^thunder:\\/\\/.+$");
	};

	this.getNameFromTorrentFile = function(filepath){
		if(filepath==null || filepath.length==0){
			return null;
		}
		if(!this.isTorrentFile(filepath)){
			return null;
		}
		return this.getFileNameWithOutSuffix(filepath);
	};
	this.getNameFromEd2kLink = function(link){
		if(link==""){
			return null;
		}
		var link = link.trim();
		var from = "ed2k://|file|".length;
		var to = link.indexOf("|",from);
		return decodeURI(link.substring(from,to));
	};
	this.getNameFromMagnetLink = function(link){
		if(link==""){
			return null;
		}
		var link = link.trim();
		var from = link.indexOf("dn=");
		if(from>0){
			from = from+3;
			var to = link.indexOf("&",from);
			var name = "";
			if(to>0){
				return decodeURI(link.substring(from,to));
			}else{
				return decodeURI(link.substring(from));
			}
		}
		return null;
	};
	
	this.getFileNameWithOutSuffix = function(filepath){
		if(filepath==null || filepath.length<=0)return "";
		var t1 = filepath.lastIndexOf("\\");
		if(t1<0){
			t1=0;
		}
		var t2 = filepath.lastIndexOf(".");
		if(t1 >= 0 && t1 < t2 && t1 < filepath.length){
		 	return filepath.substring(t1 + 1, t2);
		}
	};
	this.v_link = function(link,regexp){
		link = link.trim();
		if(new RegExp(regexp).test(link)){
			return true;
		}else{
			return false;
		}
	};
};